import random

import requests

from utils.ip import get_proxy, get_proxy_poll

proxy_poll = get_proxy_poll(3)

urls = [f"https://httpbin.org/get?age={i}" for i in range(100)]
while len(urls) :
    try:
        url = urls.pop()
        proxy = random.choice(proxy_poll)
        try:
            res = requests.get(url,proxies= proxy)
            print(res.json())
        except requests.exceptions.ProxyError as e:
            print(f"代理异常 错误原因{e}")
            proxy_poll.remove(proxy)
            proxy_poll.append(get_proxy())
        except Exception as e:
            print(f"请求地址失败 错误原因{e}")
            urls.append(url)
    except StopIteration as e:
        print(f"没有更多地址了 错误原因{e}")


